import { _decorator, Component, Node, instantiate, Vec3, Prefab, director } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('background_run')
export class background_run extends Component {
    @property
    speed = 500;

    @property(Prefab)

    bulletPre:Prefab = null
    
    static count = 0;//记录游戏结束

    start() {
        this.schedule(() =>{
            // console.log("wc")
            // director.loadScene("scene");
            if(background_run.count == 0){
                let enemy = instantiate(this.bulletPre);
                enemy.setParent(this.node.getParent());
                let p = new Vec3(Math.random()*420 - 210,515,0);//生成敌人小项目没必要再创建一个了
                
                enemy.setPosition(p);
            }
            
        },0.5)

    }

    update(deltaTime: number) {

        for(let bgNode of this.node.children){
            let p = bgNode.getPosition();
            p.y -= this.speed*deltaTime;
            if(p.y < -1100){
                p.y += 1100*2;
            }

            bgNode.setPosition(p);


        }
        
    }

}


